package utils.stack;

import java.util.ArrayList;
import java.util.List;

public class IntegerStack {
    private int top;
    private List<Integer> stack;
    private int length;
    private int maxLen;
    public IntegerStack(int maxLen){
        this.top=0;
        this.length = 0;
        this.maxLen = maxLen;
        this.stack = new ArrayList<>();
    }

    public List<Integer> getStack() {
        return stack;
    }

    public int getLength() {
        return length;
    }

    public boolean pop() {
        if (top<=0){
            return false;
        }
        top--;
        length--;
        return true;
    }

    public boolean push(Object o) {
        if (length>=maxLen){
            return false;
        }
        stack.add((Integer)o);
        top++;
        length++;
        return true;
    }

    public void travelStack(){
        System.out.println("栈中的元素为：");
        int i=top;
        while (i>0){
            System.out.print(stack.get(--i)+" ");
        }
        System.out.println();
    }
}
